package com.publish.file.service.auth;

import java.io.File;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.publish.file.common.FileUtils;
import com.publish.file.properties.SecurityProperties;

@Service
public class AuthServiceImpl implements AuthService {
	@Autowired
	SecurityProperties securityProperties;
	private Logger log = LoggerFactory.getLogger(getClass().getSimpleName());

	@Override
	public boolean vertify(String name, String password) {
		Map<String, String> propertiesMap = FileUtils.loadProperties(new File(securityProperties.getFile()));
		log.info(propertiesMap.toString());
		if (propertiesMap.containsKey(name)) {
			String passwordString = propertiesMap.get(name);
			if (passwordString != null && passwordString.equals(password)) {
				return true;
			}
		}
		return false;
	}

	@Override
	public String getPassword(String name) {
		Map<String, String> propertiesMap = FileUtils.loadProperties(new File(securityProperties.getFile()));
		return propertiesMap.get(name);
	}

}
